package com.example.demo.controller;

import com.example.demo.controller.requests.ModifyStudentRequest;
import com.example.demo.model.Student;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/stu")
public class StudentController {
    @GetMapping("/all")
    public List<Student> getAll(){
        ArrayList<Student> results = new ArrayList<>();
        results.add(Student.builder().id(1).name("张三").adminssionDate(LocalDate.parse("2019-09-01")).major("移动应用开发").build());
        results.add(Student.builder().id(2).name("李四").adminssionDate(LocalDate.parse("2019-09-02")).major("移动应用开发").build());
        results.add(Student.builder().id(3).name("王五").adminssionDate(LocalDate.parse("2019-09-03")).major("移动应用开发").build());
        return results;
    }
    //查找
    @GetMapping("/{id}")
    public Student getStudent(@PathVariable("id") Integer id){
        log.info("查询饮品的id:{}",id);
        Student student = Student.builder().id(1).name("张三").adminssionDate(LocalDate.parse("2019-09-01")).major("移动应用开发").build();
        return student;
    }
    //修改
    @PutMapping("/updata")
    public Student modifyDrink(@RequestBody ModifyStudentRequest request){
        log.info("要修改的饮品:{}",request);
        Student updatedrink = Student.builder().id(1).name("李四").adminssionDate(LocalDate.parse("2019-09-02")).major("移动应用开发").build();
        return updatedrink;
    }
    @DeleteMapping("/del/{id}")
    public String deleteName(@PathVariable Integer id ){
        log.info("要删除的名字id:{}",id);
        return "删除成功";
    }
    @PostMapping("/add")
    public Student addNewStudent(@RequestBody Student student){
        log.info("录入新的成员:{}",student);
        Student addstudent = Student.builder().id(1).name("王五").adminssionDate(LocalDate.parse("2019-09-03")).major("移动应用开发").build();
        return addstudent;
    }
}
